package com.example.zhixu.myapp2;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class BindActivity extends AppCompatActivity {

    private ServiceConnection con;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bind);
    }

    public void unbind(View view) {
    }

    public void bind(View view) {
        con = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                Spy spyProxy = (Spy)iBinder;
                Log.i("zhixu", "client..."+spyProxy.getInfo());
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {

            }
        };
        Intent intent = new Intent();
        intent.setClass(this, BindService.class);
        bindService(intent, con, BIND_AUTO_CREATE);
    }
}
